package com.diver.flinkdemo.service.impl;

import com.diver.flinkdemo.mapper.mysqlMapper.SchoolScreeningMapper;
import com.diver.flinkdemo.service.ISchoolScreeningService;
import com.diver.flinkdemo.utils.DynamicDataSourceUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author LuJW
 * @date 2023/4/4 13:26
 */
@Slf4j
public class SchoolScreeningServiceImpl implements ISchoolScreeningService {

    private SchoolScreeningMapper mapper;
    private SqlSession session;
    @Override
    public List<String> getSchoolScreening(String distinguish) {
        try {
            session = DynamicDataSourceUtil.mysqlSessionFactory.openSession(true);
            mapper = session.getMapper(SchoolScreeningMapper.class);
            List<String> schoolScreenings = mapper.getSchoolScreening(distinguish);
            return schoolScreenings;
        } finally {
            endOfSession(session);
        }
    }

    public void endOfSession(SqlSession session) {
        //关闭sqlSession
        if (session != null) {
            log.info("session commit -> session close");
//            session.commit();
            session.close();
        }
    }
}
